【例子介绍】
本源代码用于生成二维码
【源码结构】
procedure CreateQRCode(AImg: TBitMap; const ACode: String; Size: Integer);
var
QRCode: TZXingQRCodeLi;
Row, Column: Integer;
intScale: Integer;
begin
if (AImg = nil) or (Trim(ACode) = '') then Exit;
QRCode := TZXingQRCodeLi.Create(nil);
try
QRCode.Code := ACode;
QRCode.Encoding := TQRCodeEncoding(qrUTF8BOM);
QRCode.QuietZone := 1;
QRCode.Code := ACode;
intScale := AImg.Height div QRCode.Rows;
// AImg.Height := QRCode.Rows * IMG_SCALE;
// AImg.Width := QRCode.Columns * IMG_SCALE;
AImg.Width := Size;
AImg.Height := Size;
AImg.Canvas.Lock;
AImg.Canvas.Brush.Color := clWhite;
AImg.Canvas.FillRect(Rect(0, 0, AImg.Width, AImg.Height));
AImg.Canvas.Brush.Color := clBlack;
for Row := 0 to QRCode.Rows - 1 do
for Column := 0 to QRCode.Columns - 1 do
if QRCode.IsBlack[Row, Column] then
begin
AImg.Canvas.FillRect(Rect(Column * intScale, Row * intScale,
Column * intScale intScale, Row * intScale intScale));
end;
AImg.Canvas.Unlock;
finally
QRCode.Free;
end;
end;
评论